package com.ebt.m.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.ebt.m.R;
import com.ebt.m.apps.AppsView;
import com.ebt.m.cloud.ActCloudCache;
import com.ebt.m.utils.netstatus.NetChangedEvent;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by andy on 2017/8/15.
 */

public class AppsFragment extends BaseFragment {

    @BindView(R.id.recycler_view)
    AppsView appsView;
    @BindView(R.id.verify)
    TextView verify;
    @BindView(R.id.toolbar)
    Toolbar toolbar;

    public static AppsFragment newInstance() {
        AppsFragment frg = new AppsFragment();
        Bundle bundle = new Bundle();
        frg.setArguments(bundle);
        return frg;
    }

    @Override
    public void onCreateView(Bundle savedInstanceState) {
        setContentView(R.layout.frg_apps);
        ButterKnife.bind(this, contentView);
        EventBus.getDefault().register(this);
    }


    private void initData() {
        appsView.update();
    }


    @Override
    public void onResume() {
        super.onResume();
        initData();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(NetChangedEvent event) {
        if (event.onNetConnected) {
            initData();
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    @OnClick({R.id.verify})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.verify:
                getContext().startActivity(new Intent(getContext(), ActCloudCache.class));
                break;
        }
    }
}
